//
// Created on 2025/5/29.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef LINPHONEDEMO_LINPHONEMANAGER_H
#define LINPHONEDEMO_LINPHONEMANAGER_H


#include "linphone/account_creator.h"
#include "linphone/api/c-account-params.h"
#include "linphone/api/c-account.h"
#include "linphone/api/c-address.h"
#include "linphone/api/c-auth-info.h"
#include "linphone/call.h"
#include "linphone/core.h"
#include "napi/native_api.h"
#include <linphone/core.h>
#include <string>

struct CallBack {
    napi_env env_;
    napi_ref callbackRef;
    int32_t code;
};

class LinphoneManager {
    struct LinphoneData {
        LinphoneCore *lc;
        LinphoneAccount *account;
        LinphoneAuthInfo *auth_info;
    };

public:
    LinphoneManager() = default;
    int login(std::string userName, std::string pwd, std::string ip, std::string path);
    void accept_call();
    void handUp_call();
    void make_call(std::string uri);
    void setRemoteSurfaceId(std::string surfaceId);
    void destroy();
    void SetCallCallBack(napi_env env, napi_ref callBack);

private:
    std::shared_ptr<LinphoneManager::LinphoneData> linphoneData{nullptr};
    static napi_ref callBack_;
    static napi_env env_;
    
    std::string userName_;
    std::string pwd_;
    std::string ip_;
    std::string path_;
    std::string surfaceId_;
    void handleLogin();
    void ms_ohos_snd_card_register(MSFactory *factory);
    static void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg);
    static void registration_state_changed(LinphoneCore *core, LinphoneAccount *account,
                                           LinphoneRegistrationState state, const char *message);
    static void CallBackToArkts(int code);
    int testLogin(std::string userName, std::string pwd, std::string ip, std::string path, LinphoneData *linphoneData);
};

#endif // LINPHONEDEMO_LINPHONEMANAGER_H
